import redis from '../config/redis.js'

import { tags, request, summary, description, prefix, query } from 'koa-swagger-decorator'


const tag = tags(['Redis'])
@prefix("/redis")
export default class RedisController {

  @request("post", "/set")
  @summary("设置redis值")
  @description("设置redis值")
  @tag
  async setValue (ctx) {
    const body = ctx.request.body;
    console.log('body', body)
    await redis.setData(body.key, body.value);

    ctx.success(body);
  }

  @request("get", "/get")
  @summary("获取redis值")
  @description("获取redis值")
  @tag
  @query({
    key: { type: 'string', required: true, description: 'key' }
  })
  async getValue (ctx) {
    const { key } = ctx.request.query;

    const val = await redis.getData(key)

    ctx.success(val);
  }
}